﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace MyClass
{
    public class Log 
    {
        /// <summary>
        /// 日志类
        /// </summary>
        /// <param name="path">日志所在路径</param>
        /// <param name="logContent">写入内容</param>
        /// <param name="logContent">返回写入是否成功</param>
        public static string WriteLog(string path, string logContent, FileMode fileMode)
        {
            FileStream fs;
            try
            {
                if (!File.Exists(path))
                {
                    fs = File.Create(path);
                    fs.Close();
                    fs.Dispose();

                }
                else
                {
                    fs = new FileStream(path, fileMode);
                }
            }
            catch(Exception ex)
            {
                return ex.ToString();
            }
            try
            {
                using (StreamWriter sw = new StreamWriter(fs))
                {
                    sw.WriteLine(logContent);
                    sw.Close();
                    sw.Dispose();
                }
                
            }
            catch (Exception ex)
            {
                return ex.ToString();
            }
            return "写入成功!";
           
        }
    }
}
